package main

import (
	"fmt"
)

type MinStack struct {
	prest  []int //14
	backst []int // 储存最小元素
}

/** initialize your data structure here. */
func Constructor() MinStack {
	minst := new(MinStack)
	return *minst
}

func (this *MinStack) Push(x int) {
	this.prest = append(this.prest, x)
	l := len(this.backst)
	if l == 0 || x <= this.backst[l-1] {
		this.backst = append(this.backst, x)
	}
}

func (this *MinStack) Pop() {
	l := len(this.prest)
	if l <= 0 {
		return
	}
	ll := len(this.backst)
	if this.prest[l-1] == this.backst[ll-1] {
		this.backst = this.backst[0 : ll-1]
	}
	this.prest = this.prest[0 : l-1]
}

func (this *MinStack) Top() int {
	l := len(this.prest)
	return this.prest[l-1]
}

func (this *MinStack) GetMin() int {
	l := len(this.backst)
	return this.backst[l-1]
}

func main() {

	//Your MinStack object will be instantiated and called as such:
	obj := Constructor()
	obj.Push(-2)
	obj.Push(0)
	obj.Push(-3)
	fmt.Println(obj.GetMin())
	obj.Pop()
	param3 := obj.Top()
	param4 := obj.GetMin()
	fmt.Println(param3, param4)
}
